package com.esreport.service.impl;

import com.esreport.dao.StatisticsRepository;
import com.esreport.entity.Statistics;
import com.esreport.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @ClassName StatisticesServiceImpl
 * @Description
 * @Author fanxingwei
 * @Date 2020/8/26 14:03
 * @Version 1.0
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private StatisticsRepository repository;

    @Override
    public void save(Statistics statistics) {
        repository.save(statistics);

    }

    @Override
    public com.esreport.entity.Statistics getOne(Integer id) {
        return repository.getOne(id);
    }

    @Override
    public void update(Statistics statistics) {
        repository.saveAndFlush(statistics);
    }

    @Override
    public List<Statistics> getList(Integer siteId) {
        return repository.findBySiteIdOrderByDateDesc(siteId);
    }

    @Override
    public Boolean getNum(Date date, Integer siteId) {
        Integer num = repository.getNum(date,siteId);
        return num!=null&&num>0?true:false;
    }

    @Override
    public void del(Integer id) {
        repository.deleteById(id);
    }

    @Override
    public List<Statistics> getBySiteId(Integer siteId) {
        return repository.findBySiteIdOrderByDateDesc(siteId);
    }
}
